<?php

namespace app\queue\stomp;

use app\queue\BaseConsumer;
use common\service\TaskAssignService;
use Webman\Stomp\RetryAbleConsumer;

/**
 * 部门成员加入项目
 */
class AddDepartmentUserToProjectMemberConsumer extends BaseConsumer implements RetryAbleConsumer
{

    // 要消费的队列名
    public $queue = 'add_department_user_to_project_member';

    // 连接名，对应 config/redis_queue.php 里的连接`
    public $connection = 'default';

    /**
     * 任务排期
     * @param $data
     * @throws \Throwable
     */
    public function doConsume($data)
    {
        TaskAssignService::getInstance()->addDepartmentUserToProjectMember($data['department_step_category_ids_relation'], $data['project_id'], $data['role_code']);
    }

    public function getTtr()
    {
        return 20;
    }

    public function canRetry($attempt, $error)
    {
        trace(format_exception_info($error), 'ERR');
        return $attempt <= 3;
    }
}
